<template>
  <div>
    <el-card>
      <el-row :gutter="20">
        <el-col :span="3">
          <el-input placeholder="请输入手机号" size="small" class="input-with-select" v-model="queryInfo.mobile"/>
        </el-col>
        <el-col :span="4">
          <el-select v-model="queryInfo.status" placeholder="状态">
            <el-option label="全部" value=""></el-option>
            <el-option label="交易完成" value="S"></el-option>
            <el-option label="交易关闭" value="N"></el-option>
          </el-select>
        </el-col>
        <el-col :span="4">
          <el-select v-model="queryInfo.typeList" multiple  placeholder="类型">
            <el-option label="全部" value=""></el-option>
            <el-option label="支付宝-充值" value="ali_charge"></el-option>
            <el-option label="管理员-充值" value="manager_charge"></el-option>
            <el-option label="交易扣款" value="trade"></el-option>
            <el-option label="退款" value="refund"></el-option>
          </el-select>
        </el-col>
        <el-col :span="3">
          <el-button type="primary" size="small" style="margin-left: 10px;" @click="getTrsFlowList">搜索</el-button>
        </el-col>
        <el-col :span="4">
          <el-button type="primary" size="small" @click="showEditDialog('')">添加</el-button>
        </el-col>
      </el-row>
    </el-card>
    <el-card>
      <el-table :data="trsFlowList" border stripe>
        <el-table-column label="ID" prop="id" width="70"></el-table-column>
        <el-table-column label="手机号" prop="mobile"></el-table-column>
        <el-table-column label="金额" prop="amount"></el-table-column>
        <el-table-column label="账户余额" prop="balance"></el-table-column>
        <el-table-column label="关联订单Id" prop="orderId"></el-table-column>
        <el-table-column label="类型" prop="typeDesc"></el-table-column>
        <el-table-column label="订单状态" prop="orderStatusText" width="70">
          <template slot-scope="scope">
            <span type="primary" v-if="scope.row.status=='S'">交易完成</span>
            <span type="primary" v-if="scope.row.status=='N'">交易关闭</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" prop="remark"></el-table-column>
        <el-table-column label="管理员" prop="userName"></el-table-column>
        <el-table-column label="交易时间" prop="addTime"></el-table-column>
      </el-table>

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                     :current-page="queryInfo.pageNo" :page-sizes="[5, 10, 20, 40, 60]"
                     :page-size="queryInfo.pageSize" layout="total, sizes, prev, pager, next, jumper"
                     :total="total">
      </el-pagination>
    </el-card>

    <el-dialog title="添加充值记录" :visible.sync="editDialogVisible" width="40%" @close="editDialogClosed">
      <el-form :model="editForm" ref="editFormRef" label-width="90px" class="demo-ruleForm">
        <el-form-item label="手机号" prop="mobile">
          <el-input v-model="editForm.mobile" style="width: 180px;"></el-input>
        </el-form-item>
      </el-form>
      <el-form :model="editForm" ref="editFormRef" label-width="90px" class="demo-ruleForm">
        <el-form-item label="金额" prop="amount">
          <el-input v-model="editForm.amount" style="width: 100px;"></el-input>
        </el-form-item>
      </el-form>

      <el-form :model="editForm" ref="editFormRef" label-width="90px" class="demo-ruleForm">
        <el-form-item label="备注" prop="remark">
          <el-input type="textarea" v-model="editForm.remark"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveTrsFlow()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Api from "@/api/MemberAccountTrsFlow.js";

export default {
  data() {
    return {
      drawer: false,
      dialogVisible: false,
      disabled: false,
      queryInfo: {
        id: "",
        mobile: '',
        status: '',
        typeList: [],
        pageNo: 1,
        pageSize: 40, // 页大小
      },
      editDialogVisible: false,
      editForm: {
        id: ''
      },
      trsFlowList: [],
      total: 0
    };
  },
  created() {
    this.getTrsFlowList();
  },
  methods: {
    getTrsFlowList() {
      Api.getTrsFlowList(this.queryInfo).then((res) => {
        if (res.success) {
          this.trsFlowList = res.data.records;
          this.total = res.data.total;
        } else {
          return this.$message.error("获取列表失败");
        }
      });
    },
    saveTrsFlow() {
      Api.saveTrsFlow(this.editForm).then((res) => {
        if (res.success) {
          this.$message.success("保存成功");
          this.editDialogVisible = false;
          this.getTrsFlowList();
        } else {
          return this.$message.error("保存失败：" + res.msg);
        }
      });
    },
    async showEditDialog(id) {
      Api.getTrsFlow({'id': id}).then(res => {
        if (res.success) {
          this.editForm = res.data
          this.editDialogVisible = true
        } else {
          return this.$message.error('查询失败')
        }
      })
    },
    editDialogClosed() {

    },
    handleSizeChange(pageSize) {
      this.queryInfo.pageSize = pageSize;
      this.getTrsFlowList();
    },
    handleCurrentChange(pageNo) {
      this.queryInfo.pageNo = pageNo;
      this.getTrsFlowList();
    },
  }
};
</script>

<style lang="less" scoped>
.logo_pic {
  max-width: 100px;
}

.upload_img {
  width: 148px;
  height: 148px;
  object-fit: cover;
  border-radius: 6px;
  margin-right: 20px;
}
</style>
